﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrBitDataAcquisition.Common
{
    public static class StartupManager
    {
        private const string RegistryRunPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";

        public static void SetStartup(string appName, string appPath, bool enable)
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RegistryRunPath, true))
            {
                if (enable)
                {
                    // 设置开机启动
                    key.SetValue(appName, $"\"{appPath}\"");
                }
                else
                {
                    // 取消开机启动
                    key.DeleteValue(appName, false);
                }
            }
        }
    }
}
